﻿/*============================================================================================
	TASK 7:                                                      {Strings And Text Processing}
	Write a program that extracts from a given text all sentences containing given word.
 
	Example:
    The word is: "in".
    The text is:"We are living in a yellow submarine. We don't have anything else.
                 Inside the submarine is very tight. So we are drinking all the day.
                 We will move out of it in 5 days."
  
    The expected result is:
                 We are living in a yellow submarine.
                 We will move out of it in 5 days.

    Consider that the sentences are separated by "." and the words – by non-letter symbols.
=============================================================================================*/

using System;
using System.Text.RegularExpressions;

    class ExtractSentences
    {
        static void Main()
        {
            string text = "We are living in a yellow submarine.We don't have anything else. Inside the submarine is very tight. So we are drinking all the day. We will move out of it in 5 days.";
            Console.WriteLine(text);
            Console.WriteLine();

            string word = "in";
            string[] sentences = text.Split('.');

            for (int i = 0; i < sentences.Length; i++)
            {
                /*
                    The \b metacharacter is used to find a match at the beginning or end of a word.
                    If no match is found, it returns null.
                    info source:http://www.w3schools.com/jsref/jsref_regexp_begin.asp 
                 */

                if (Regex.Matches(sentences[i], @"\b" + word + @"\b").Count > 0)
                {
                    Console.WriteLine((sentences[i] + ".").Trim());
                }
            }

            Console.WriteLine();
        }
    }

